package 补充.多线程;
class Ticket2 implements Runnable{
    private int ticket=5;
    @Override
    public synchronized void run() {
        while(true){

                if(ticket>0){
                    try {
                        Thread.sleep(100);
                    }catch(InterruptedException e){
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+"卖出第"+ticket+"张票，还剩"+--ticket+"张票");
                }

        }
    }
}
public class 同步方法 {
    public static void main(String[] args) {
        Ticket2 ticket2=new Ticket2();
        Thread t1 = new Thread(ticket2,"窗口一");
        Thread t2 = new Thread(ticket2,"窗口二");
        Thread t3 = new Thread(ticket2,"窗口三");
        t1.start();
        t2.start();
        t3.start();
    }
}
